//
//  MEShortcutMenuViewController.swift
//  aj
//
//  Created by leeqb on 11/22/15.
//  Copyright © 2015 powerlee. All rights reserved.
//

import UIKit

class MEShortcutMenuViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    let menus = [["title":"资料管理","img":"me_icon_profile"],
        ["title":"家的安全","img":"me_icon_security"],
        ["title":"我建我家","img":"me_icon_family"],
        ["title":"推荐给好友","img":"me_icon_recommand"]
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    // MARK: - UICollectionViewDelegateFlowLayout
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSize(width: (SCREEN_WIDTH-20)/CGFloat(menus.count), height: (self.collectionView?.frame.width)!)
    }
    
    // MARK: UICollectionViewDataSource
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return menus.count
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MenuCell", forIndexPath: indexPath)
    
        let imageView = cell.viewWithTag(1) as! UIImageView
        let textLabel = cell.viewWithTag(2) as! UILabel
        
        let dict = menus[indexPath.row]
        imageView.image = UIImage(named: dict["img"]!)
        textLabel.text = dict["title"]
        
        return cell
    }
    
    // MARK: - UICollectionViewDelegate
    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        switch indexPath.row {
        case 0: // 资料管理
            let dataVC = LB("Me", vcName: "MyData") as! MEMyDataViewController
            self.navigationController?.pushViewController(dataVC, animated: true)
            break
        case 1: // 家的安全
            let vc = LB("Security", vcName: "SecurityMenuVC") as! SECMenuViewController
            self.navigationController?.pushViewController(vc, animated: true)
            break
        case 2: // 我建我家
            break
        case 3: // 推荐给好友
            ShareView.show()
            break
        default:
            break
        }
    }

}
